/**
 * Created by L.jp
 * Description:
 * User: 86189
 * Date: 2021-10-12
 * Time: 23:50
 */

class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;

    public TreeNode(int val) {
        this.val = val;

    }

}
public class BinaryTree {
    TreeNode prev=null;
    public void ConvertChild(TreeNode pcur) {
        if(pcur==null){
            return;
        }
        ConvertChild(pcur.left);
        pcur.left=prev;
        if(prev!=null){
            prev.right=pcur;
        }
        prev=pcur;
        ConvertChild(pcur.right);
    }
    public TreeNode Convert(TreeNode pRootOfTree) {
        if(pRootOfTree==null){
            return null;
        }
        ConvertChild(pRootOfTree);
        TreeNode head=pRootOfTree;
        while(head.left!=null){
            head=head.left;
        }
        return head;
    }
}

